package com.dime.basic.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.dime.basic.api.domain.DimeBasegroup;
import com.ruoyi.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.dime.basic.service.IDimeBasegroupService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 科室管理Controller
 *
 * @author Tiny
 * @date 2023-09-12
 */
@RestController
@RequestMapping("/basegroup")
public class DimeBasegroupController extends BaseController
{
    @Autowired
    private IDimeBasegroupService dimeBasegroupService;

    /**
     * 查询科室管理列表
     */
    @RequiresPermissions("basic:basegroup:list")
    @GetMapping("/list")
    public TableDataInfo list(DimeBasegroup dimeBasegroup)
    {
        startPage();
        List<DimeBasegroup> list = dimeBasegroupService.selectDimeBasegroupList(dimeBasegroup);
        return getDataTable(list);
    }

    /**
     * 导出科室管理列表
     */
    @RequiresPermissions("basic:basegroup:export")
    @Log(title = "科室管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DimeBasegroup dimeBasegroup)
    {
        List<DimeBasegroup> list = dimeBasegroupService.selectDimeBasegroupList(dimeBasegroup);
        ExcelUtil<DimeBasegroup> util = new ExcelUtil<DimeBasegroup>(DimeBasegroup.class);
        util.exportExcel(response, list, "科室管理数据");
    }

    /**
     * 获取科室管理详细信息
     */
    @RequiresPermissions("basic:basegroup:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(dimeBasegroupService.selectDimeBasegroupById(id));
    }

    /**
     * 新增科室管理
     */
    @RequiresPermissions("basic:basegroup:add")
    @Log(title = "科室管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DimeBasegroup dimeBasegroup)
    {
        return toAjax(dimeBasegroupService.insertDimeBasegroup(dimeBasegroup));
    }

    /**
     * 修改科室管理
     */
    @RequiresPermissions("basic:basegroup:edit")
    @Log(title = "科室管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DimeBasegroup dimeBasegroup)
    {
        return toAjax(dimeBasegroupService.updateDimeBasegroup(dimeBasegroup));
    }
    /**
     * 删除科室管理
     */
    @RequiresPermissions("basic:basegroup:delete")
    @Log(title = "科室管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove1(@PathVariable String[] ids)
    {
        return toAjax(dimeBasegroupService.deleteDimeBasegroupByIds(ids));
    }


	@GetMapping("/info/groups/{ids}")
    public R<List<DimeBasegroup>> remove(@PathVariable String[] ids)
    {
        return R.ok(dimeBasegroupService.selectDimeBasegroupByIds(ids));
    }

    @GetMapping("/info/groupUser/{userId}")
    public R<List<DimeBasegroup>> getGroupByUserId(@PathVariable String userId)
    {
        return R.ok(dimeBasegroupService.selectDimeBasegroupByUserId(userId));
    }


    @GetMapping("/info/getallgroup")
    public R<List<DimeBasegroup>> getallgroup()
    {
        DimeBasegroup dimeBasegroup=new DimeBasegroup();
        return R.ok(dimeBasegroupService.selectDimeBasegroupList(dimeBasegroup));
    }
}
